﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CoreRay.IO
{
    public class FileSystemResourceReader : ResourceReader
    {
        private string basePath; 

        public FileSystemResourceReader(string basePath)
        {
            this.basePath = basePath;
        }

        public override bool ResourceExists(string path)
        {
            if (this.basePath == null)
            {
                return File.Exists(string.Format("{0}", path));
            }

            else
            {
                return File.Exists(string.Format(@"{0}\{1}", this.basePath, path));
            }
        }

        public override Stream OpenResource(string path)
        {
            if (this.basePath == null)
            {
                return new FileStream(string.Format("{0}", path), FileMode.Open, FileAccess.Read);
            }

            else
            {
                return new FileStream(string.Format(@"{0}\{1}", this.basePath, path), FileMode.Open, FileAccess.Read);
            }
        }
    }
}
